export const errmiddleware = (err,req,res,next)=>{
    if(err){
        const {name,code,message} = err;
        let msg = ""
        if(name === "MongoServerError"){
            if(code === 11000){
                msg = "值重复"
            }
        }else if(message === "Cannot read properties of undefined (reading 'toUpperCase')"){
            msg = "验证码错误"
        }
        console.log(err);
        
        // TODO 封装一个错误函数
        res.json({code:1,msg})
    }
    next();
}